<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/multiselect.css" />
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/btn.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/user/ujscb.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/uploadphoto.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/xxs.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/homeside.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/ja.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript" src="${aier_js_url}social/user/userHSConBook/teabook.js"></script>

</head>
<script type="text/javascript">
	var global_suffix = "${aier_suffix}", global_url = "${aier_url}", global_uri = "${aier_uri}", global_urijs = "${aier_urijs}", 
		global_sid = "${sid}",global_cid = "${cid}", global_tid = "${tid}",global_userin_url = "${video_user_in_url}",global_userout_url = "${video_user_out_url}";
</script>
<body data-usertype="学校管理员（校长）" class="view-ujscb">
	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user" executeResult="true"></s:action>

	<div class="window-content">

		<!-- wrap  -->

		<div class="wrap clearfix">

			
			<!-- 左侧导航栏  -->
			<div class="nav-side">
				<!-- 家校联系簿（管理员） 头像 -->
				<div class="ujscb-userinfo">
					<dl class="clearfix">
						<dt style="" data-log="头像" class="avatar">
							<a href="${aier_url}user/uccomm_userCenter.shtml"> <img src="${get_picturl_url}small/${userInfo.headimg}"></a>
						</dt>

						<dd class="nickname">
							<a href="${aier_url}user/uccomm_userCenter.shtml">${userInfo.nickname}</a>
						</dd>
						
						<dd>
						    <div class="explain">
                                <span id = "mesCount"></span>
                            </div>
						</dd>

					</dl>
				</div>
				<!-- / 管理员头像 -->

				
			</div>
			<!-- // 左侧导航栏  -->

			<!-- 主区域 (右  -->
			<div class="main-area clearfix">

				<!-- 中间栏 -->
				<div class="message-stream">
					<div class="stream-main">
						<div class="right-main-top">
							<div class="binfo-title" id="title">
								<h3>家校联系簿</h3>
							</div>
						</div>

						<div class="sendBox">
							<div id="teaSendTabs">
								<ul>
									<li><a href="#inputBroadcast">公告</a></li>
								</ul>
								<!-- 公告 -->
								<div id="inputBroadcast">
								
									<!-- 选择发送对象 -->
								
										<span>发送对象：</span>
										<span>
											<!-- <a href="javascript:;" style="color:#0033CC;">全部教工</a> -->
											<a id="selTeaClBtn" href="javascript:;" style="color:#FF9900">选择</a>
										</span>
								
								
									<!-- /选择发送对象 -->
								
								
									<!-- 教工班级选择弹出层 -->
									<div id="selTeaAndCl" style="display:none;">
										<div class="nav">
											<span><a class="btn-sort-teacher current">按教职工选择</a></span>
											<span>|</span>
											<span><a class="btn-sort-class">按班级选择</a></span>
										</div>
										<div class="list">
											<div class="list-teacher open">
												<div class="select-all">
													<label><input type="checkbox" value="全选">全体教师</label>
												</div>
												<hr>
												<div class="select-onebyone clearfix">
												    <c:forEach var="sg" items="${schoolTeacher }">
                                                        <label><input type="checkbox" value="${sg.tid}">${sg.tname}</label>
                                                    </c:forEach>
												</div>
											</div>
											
											<div class="list-class">
												<div class="select-all">
													<label><input type="checkbox" value="全选">全体师生</label>
												</div>
												<hr>
												<div class="select-onebyone clearfix">
												    <c:forEach var="sg" items="${classList}">
                                                        <label><input type="checkbox" value="${sg.cid}">${sg.cname}</label>
                                                    </c:forEach>
													
												</div>
											</div>
											
										</div>
										
									</div>
									
									<!-- /选择发送对象弹出层 -->
								
									<div class="input-box clearfix">
										<textarea class="placeholder" id="schoolmessageText"
											placeholder="公告会同步显示在班级黑板上哦！"
											maxcount="240" data-input-limit-uid="1"
											data-prevcolor="rgb(0, 0, 0)"
											style="color: rgb(170, 170, 170);"></textarea>
									</div>
									<div class="input-bottom clearfix">
										<span class="fr word-limit" style="visibility: hidden;">还可以输入<em>240</em>个字</span>
										<span class="doupload"> <a href="javascript:;"
											class="upload_img">图片</a> <!-- &nbsp;| --> <a
											href="javascript:;" class="upload_video"
											style="visibility: hidden;">视频</a> <a href="javascript:;"
											class="upload_attach" style="visibility: hidden;">附件</a> </span>
										<div style="display: none;" class="upload_oper_panel">
											<div class="inner_panel img_panel" style=""></div>
										</div>
									</div>
									<div class="sendOth">
										<!---->
										
										<label for="sendPhoneMsg"><input id="sendPhoneMsg" type="checkbox" value="">同时发送免费手机短信</label> 
											
										<a href="javascript:;" id="schoolmessageSend"
											class="button sendBtn"><em>发送</em> </a>
									</div>
									 
								</div>

							</div>

							<div id="teaShowTabs">
								<ul>
									<li><a href="#userBulletin" id = "bulletin">公告</a></li>
								</ul>
								<!-- 公告 -->
								<div id="userBulletin">
								</div>

							</div>
						</div>
					</div>
					<div id = "page"></div>
				</div>

                <div id="messageConfirm" style="display: none;" title="短信发送确认">
                        <span>发布此公告将会发送短信 <span id="mcount"></span> 条</span>
                </div>

				
			</div>
				<a id="goTopBtn" class="ae-gotop icon-2 icon-2-btt"
					href="javascript:;"></a>
		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user" executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>
<!-- 上传图片弹出框 -->
<div id="uploadPhotoBox" style="z-index:999;display:none;">
	<div class="title">上传图片</div>

	<div class="select">

		<a class="btn-select">
			<label for="selectPhoto">
			<span>选择图片</span>
			</label>
		</a>

		<input type="file" id="selectPhoto" style="" name="selectPhoto">
	</div>

	<div class="uploading" style="display:none">正在上传</div>

	<div id="confirmPhoto" style="display:none">
		<div id="photoName"></div>
		<div id="delete">x</div>
	</div>
	<div id="deleteConfirm" style="display: none;" title="删除">
	    <p>你确定要删除这条公告吗?</p>
	</div>

</div>
<!-- /上传图片弹出框 -->
</body>
<script type="text/javascript">
    var bpage = 1;       // 公告的当前页
    var page_size = 10; // 每页的记录数
    var sname = "${sname}"; // 学校的名称
	var hwImg = "";
	$("#teaSendTabs").tabs();
	$("#teaShowTabs").tabs();
	$(".chosen").chosen();

	//返回顶部悬浮按钮
	$(document).ready(function() {
		//首先将#back-to-top隐藏
		$("#goTopBtn").hide();
		//当滚动条的位置处于距顶部100像素以下时，跳转链接出现，否则消失
		$(function() {
			$(window).scroll(function() {
				var a = $(window).scrollTop(), b = $(window).outerHeight();
				if (a > 100) {
					$("#goTopBtn").css({
						'display' : 'block',
						'top' : a + b - 200
					});
				} else {
					$("#goTopBtn").css('display', 'none');
				}
			});
			//当点击跳转链接后，回到页面顶部位置，数字越小则越快
			$("#goTopBtn").click(function() {
				$('body,html').animate({
					scrollTop : 0
				}, 800);
				return false;
			});
		});

	});

	//文本输入框与textare切换
	//文本框获得焦点
	$(".txt_ipt").focus(function() {
		$(this).hide();
		$(this).closest('.fd-right').find('.comment_input_box').show();
		$(this).closest('.fd-right').find('.comment_input_box textarea').focus();
	});

	$(document)
			.ready(
					function() {
						var fun = function(data) {
                            if (data.s == 1) {
                                var st = data.st;
                                if (st == null || st.isadmin ==0 ) {
                                	$().message("您没有权限进入此家校联系薄");
                                	window.history.back();
                                } else {
                                	$("#title").html("<h3>家校联系薄-" + sname + "</h3>");
                                	global_tid = st.tid;
                                	if (data.method == 2) {
                                	   $("#mesCount").text("剩余短信"+data.mesCount+"条");
                                	}
                                    // 获取公告列表
                                    searchSchoolMessage(bpage);
                                }
                            }
                        };
                        exeAjax(
                                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchSchoolBySidUid${aier_suffix}"),
                                fun, {
                                    "sid" : global_sid
                                });
						
					});
	
	// 学校管理员发布公告，先确认短信发送
    $("#schoolmessageSend")
            .click(
                    function() {
                        var content = $("#schoolmessageText").val();
                        if (null == content || "" == content) {
                            $().message("请输入公告内容!");
                            return;
                        }
                        var isSendPhone = false;
                        if ($('#sendPhoneMsg').attr("checked") == "checked") {
                            isSendPhone = true;
                        }
                        if(isAllTeacher==false&&isAllClass==false&&isnull(tidList)&&isnull(cidList)){
                            $().message("请选择公告的发送对象");
                            return;
                        }
                        // 发送短信
                        if (isSendPhone) {
                        	var fun = function(data) {
                                if (data.s == 1) {
                                	$('#mcount').text(data.mesCount);
                                	$(function() {
                                        $("#messageConfirm").dialog(
                                            {
                                                //背景变暗
                                                modal : true,
                                                autoOpen : false,
                                                show : "fade",
                                                hide : "fade",
                                                width : "340",
                                                height : "220",
                                                buttons : {
                                                    "确定" : function() {
                                                        //发布公告
                                                        publishBlletin(content,isSendPhone);
                                                        $(this).dialog("close");
                                                    },
                                                    "取消" : function() {
                                                        $(this).dialog("close");
                                                    }
                                            }
                                        });
                                        $("#messageConfirm").dialog("open");
                                    });
                                    
                                }
                            };
                            exeAjax(
                                    ajaxUrl("${aier_url}${aier_urijs}userhscb_searchMessageCount${aier_suffix}"),
                                    fun, {
                                        "sid" : global_sid,
                                        "tid" : global_tid,
                                        "cid" : global_cid,
                                        "imageName" : hwImg,
                                        "content" : content,
                                        "isSendPhone" : isSendPhone,
                                        "isAllTeacher" : isAllTeacher,
                                        "isAllClass" : isAllClass,
                                        "tidList_temp" : tidList.toString(),
                                        "cidList_temp" : cidList.toString()
                                        
                                    });
                        } else {
                        	// 发布公告
                        	publishBlletin(content,isSendPhone);
                        }
                        

            });
	// 发布公告
	function publishBlletin(content,isSendPhone) {
		var fun = function(data) {
            if (data.s == 1) {
                $("#schoolmessageText").val("");
                hwImg = "";
                $('#sendPhoneMsg').attr("checked",false);
                $('#confirmPhoto').hide();
                $('#selectPhoto').val("");
                $('#photoName').html("");
                $('.select').show();
                $().message("公告发布成功!");
                $("#mesCount").text("剩余短信"+data.mesCount+"条");
                // 获取公告列表
                searchSchoolMessage(bpage);
            }else if(data.s == 2) {
                $().message("剩余短信数量不足，短信发送失败！");
                $("#schoolmessageText").val("");
                hwImg = "";
                $('#sendPhoneMsg').attr("checked",false);
                $('#confirmPhoto').hide();
                $('#selectPhoto').val("");
                $('#photoName').html("");
                $('.select').show();
                // 获取公告列表
                searchSchoolMessage(bpage);
            }else{
                $().message("公告发布失败!"+data.error_info);
            }
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_addSchoolMessage${aier_suffix}"),
                fun, {
                    "sid" : global_sid,
                    "tid" : global_tid,
                    "cid" : global_cid,
                    "imageName" : hwImg,
                    "content" : content,
                    "isSendPhone" : isSendPhone,
                    "isAllTeacher" : isAllTeacher,
                    "isAllClass" : isAllClass,
                    "tidList_temp" : tidList.toString(),
                    "cidList_temp" : cidList.toString()
                    
                });
	}
	
	
    $("#bulletin").click(function() {
        $("#page").css("display","block");
        searchSchoolMessage(bpage);
    });
    
    //查询公告
    function searchSchoolMessage(nowbpage){
        bpage = nowbpage;						
        var fun = function(data) {
        	var meghtml = "";
            if (data.s == 1) {
                for(var i=0;i<data.schoolMessageList.length;i++) {
                  	var name_teacher = data.schoolMessageList[i].name_teacher;
                  	var headimg_teacher = data.schoolMessageList[i].headimg_teacher;
     				var message = data.schoolMessageList[i].message;
     				var ctime_str = data.schoolMessageList[i].ctime_str;
     				var type_m = data.schoolMessageList[i].type;
     				var img = data.schoolMessageList[i].img;
     				var tid = data.schoolMessageList[i].tid;
     				var type_str = "班级公告";
     				if(type_m==0){
     					type_str = "校园公告";
     				};
     				var successStr = data.schoolMessageList[i].successStr;
                    var failStr = data.schoolMessageList[i].failStr;
     				meghtml += "<div class='fd-item'><dl class='clearfix'><dt><a class='fd-actor' href=''> <img width='50' height='50' data-card='392161'"+
     					"src='${get_picturl_url}small/"+headimg_teacher+"' alt='"+name_teacher+"' title='"+name_teacher+"'> </a></dt>"+
     					"<dd class='fd-right'><div class='fd-top'><span><a href=''>"+name_teacher+"老师</a>发布了"+type_str+"</span>"+
     					"<div>"+message+"</div>";
     				// 有图片
                    if (!isnull(img)) {
                        meghtml += "<div class='feed_media'><span data-action='showMediaBox'><a href='${homework_get_url}origin/"+
                        img+"' target='_blank'><img src='${homework_get_url}small/"+img+"' class='small_pic'></a></span></div>";
                    }
     				
                    meghtml += "</div>";
                    // 班级公告显示短信成功和失败用户，学校公告不显示
                    if (type_m != 0) {
                    	var mes = "";
                        if (!isnull(successStr)) {
                            mes = "短信发送成功用户："+successStr;
                            if (!isnull(failStr)) {
                                mes = mes + "; 短信发送失败用户："+failStr;
                            }
                        } else {
                            if (!isnull(failStr)) {
                                mes = mes + "短信发送失败用户："+failStr;
                            }
                        }
                        meghtml += "<p class='fd-message'>"+mes+"</p>"; //短信成功和失败
                    }
                    
                    meghtml += "<p class='fd-bottom'><span class='time'>"+ctime_str+"</span></p></dd>";
                    if (global_tid == tid) {
                        meghtml += "<div class='xxs-screen'><a href='javascript:void(0);' class='btn-screen-delete' onclick='deleteMessage("+data.schoolMessageList[i].mid+");'>x</a></div>";
                    }
                    meghtml += "</dl></div>";
     			}
     			// 更新分页显示
     			bpage = data.page;
                toLoadPage(bpage, page_size, data.page_count, data.count, "page", "searchSchoolMessage", null, null);
                if (data.count == 0) {
                    $("#page").css("display","none");
                } else {
                    $("#page").css("display","block");
                }
            };
            $("#userBulletin").html(meghtml);
        };
        exeAjax(
                ajaxUrl("${aier_url}${aier_urijs}userhscb_searchSchoolMessageList${aier_suffix}"),
                fun, {
                	"sid" : global_sid,
                    "tid" : global_tid,
                    "cid" : global_cid,
                    "page":bpage,
                    "page_size":page_size
                });   
    }
    
    
    
// 上传图片

$("body").click(function(){
 	$("#uploadPhotoBox").hide();
});

$('.upload_img,#uploadPhotoBox').click(function(event) {
    event.stopPropagation();
});

$(".upload_img").click(function() {
	
 	var boxTop = $(this).offset().top + $(this).height() + 8,
 		boxLeft= $(this).offset().left;
 	
    $('#uploadPhotoBox').css({
   	 top: boxTop,
        left: boxLeft
   });
 
    $('#uploadPhotoBox').toggle();

});





	$("#selectPhoto").live('change', function(){
		upfile();
		$(".select").hide();
		$(".uploading").show();
	});
	
	function upfile() {
	    var temp = $('#selectPhoto').val().substring($('#selectPhoto').val().lastIndexOf('.')).toLowerCase();
		try {$.ajaxFileUpload({
			url : "${aier_url}commonjs/image_uploadImage${aier_suffix}?photoName="+temp+"&&imageUrl=${homework_upload_url}&&type=1",
            secureuri : false,
			fileElementId : 'selectPhoto',
			dataType : 'json',
			success : function(data, status) {
			    if (data.s == 1) {
				    hwImg = data.imageName;
	                $(".uploading").hide();
	                $('#confirmPhoto').show();
	                $('#photoName').html(hwImg);
			    } else {
			        $().message("图片上传出错，请重新上传！");
			        $(".uploading").hide();
                    $('.select').show();
			    }
				
			},
			error : function(data, status, e) {
				$().message("服务器连接超时");
				
			}
		});
		} catch (e) {
			$(".uploading").hide();
			$('.select').show();
			$().message("服务器连接超时");
		}
	};
	
	// 删除图片
	$("#delete").click(function(){
       
         var fun=function(data){
            if(data.s==1){
                hwImg = "";
                $('#confirmPhoto').hide();
                $('#selectPhoto').val("");
                $('#photoName').html("");
                $('.select').show();
            } else {
                $().message("删除失败，请稍后再试！"); 
            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}userhomeforums_deleteImage.shtml"),
             fun,{
                 "imageName":hwImg
        });
	    
	});
	
	
	$("#daily").click(function() {
	   $("#page").css("display","none");
	});
	

	
	var isAllTeacher = false;	//是否全体教师
    var isAllClass = false;		//是否全体师生
    var tidList;		//教师tid列表--发送短信 选择使用
    var cidList;		//班级cid列表--发送短信 选择使用
	/*   选择发送对象 - dialog       */
	
	var type ='';



	$('#selTeaClBtn').click(function(){
		isAllTeacher = false;
	    isAllClass = false;
		tidList = [];
		cidList = [];
		$('#selTeaAndCl input').removeAttr('checked');
		
		$("#selTeaAndCl").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "fade",
	        hide : "fade",
			width : "610",
			height : "400",
			buttons: {
				"确定": function() {
					if ( $('#selTeaAndCl .list-teacher').hasClass('open') ) {
						var label = $('#selTeaAndCl .list-teacher .select-onebyone').find('label');
						var length = label.length;
						for (var i=0; i<length; i++) {
							var input = label.children('input').eq(i);
							var inputChecked = input.attr('checked');
							if ( inputChecked == 'checked' ) {
								tidList.push( input.val() );
							}
						}

						
					} else {

						var label = $('#selTeaAndCl .list-class .select-onebyone').find('label');
						var length = label.length;
						for (var i=0; i<length; i++) {
							var input = label.children('input').eq(i);
							var inputChecked = input.attr('checked');
							if ( inputChecked == 'checked' ) {
								cidList.push( input.val() );
							}
						}
						
					}
					
					if (cidList.length == 0 && tidList.length == 0) {
						$().message('您还没有选择哦~');
					} else {
						$('#selTeaClBtn').text('已选择，点击重新选择');
						$( this ).dialog( "destroy" );
					}

				},
				"取消": function() {
					$('#selTeaClBtn').text('选择');
					$( this ).dialog( "destroy" );
					
				}
			}
		});
		
		
		$("#selTeaAndCl").dialog("open");

		
		
		// 切换
		$('#selTeaAndCl .btn-sort-teacher').click(function(){
			if (!$(this).hasClass('current')) {
				$('#selTeaAndCl .btn-sort-class').removeClass('current');
				$('#selTeaAndCl .list-class').removeClass('open');
				$('#selTeaAndCl .list-class input').removeAttr('checked disabled');
				$(this).addClass('current');
				$('#selTeaAndCl .list-teacher').addClass('open');
			}
		});
		
		$('#selTeaAndCl .btn-sort-class').click(function(){
			if (!$(this).hasClass('current')) {
				$('#selTeaAndCl .btn-sort-teacher').removeClass('current');
				$('#selTeaAndCl .list-teacher').removeClass('open');
				$('#selTeaAndCl .list-teacher input').removeAttr('checked disabled');
				$(this).addClass('current');
				$('#selTeaAndCl .list-class').addClass('open');
			}
		});
		
		$('#selTeaAndCl .select-all input').click(function(){
			if ($(this).attr('checked') == 'checked' ) {
				$(this).closest('.open').find('.select-onebyone input').attr({checked:'checked',disabled:'disabled'});
				if( $('#selTeaAndCl .list-teacher').hasClass('open') ) {
					isAllTeacher = true;
				} else {
					isAllClass = true;
				}
			} else {
				$(this).closest('.open').find('.select-onebyone input').removeAttr('checked disabled');
				isAllClass = false;
				isAllTeacher = false;
			}
		});
		

	});
	
	//删除公告
	function deleteMessage(mid) {
	    $(function() {
	        $("#deleteConfirm").dialog(
	            {
	                //背景变暗
	                modal : true,
	                autoOpen : false,
	                show : "fade",
	                hide : "fade",
	                width : "340",
	                height : "220",
	                buttons : {
	                    "确定" : function() {
	                        // 获取公告列表
	                        var fun=function(data){
	                            if(data.s==1){
	                                $("#deleteConfirm").dialog("close");
	                                searchSchoolMessage(bpage);
	                            } else {
	                                $("#deleteConfirm").dialog("close");
	                                $().message("删除失败，请稍后再试！");
	                            }
	                            
	                        };
	                        exeAjax(
	                             ajaxUrl("${aier_url}${aier_urijs}userhscb_deleteMessage${aier_suffix}"),
	                             fun,{
	                                "mid":mid
	                        });
	                                        },
	                    "取消" : function() {
	                        $(this).dialog("close");
	                    }
	            }
	        });
	        $("#deleteConfirm").dialog("open");
	    });
	}
		
</script>
</html>